<template>
  <div class="publish-wrapper">
    <div class="publish-mask"></div>
    <div class="publish-banner-wrapper">
      <div class="publish-banner">
        <div class="publish-content clearfix">
          <a href="javascript:;" class="publish-close" @click="close()">
            <i class="fas fa-times"></i>
          </a>
          <div
            class="publish-header clearfix"
            style="text-align: center; font-weight: 600; font-size: 18px"
          >
            <p style="margin: 0">
              <span>发布需求</span>
            </p>
          </div>
          <div class="publish-main">
            <div class="publish-message-box">
              <div class="publish-item">
                <div class="publish-item-name">
                  <span class="required">*</span>
                  需求名称
                </div>
                <div class="item-input-wrapper">
                  <input
                    class="publish-input"
                    type="text"
                    placeholder="请填写名称"
                  />
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">
                  <span class="required">*</span>
                  团队
                </div>
                <div class="item-input-wrapper">
                  <label class="radio-input-wrapper">
                    <input
                      type="radio"
                      class="publish-input publish-radio-input"
                      name="team-radio"
                      value="企业"
                    />
                    <span class="radio">
                      <span class="radio-inner"> </span>
                    </span>
                    企业
                  </label>
                  <label class="radio-input-wrapper">
                    <input
                      type="radio"
                      class="publish-input publish-radio-input"
                      name="team-radio"
                      value="个人"
                    />
                    <span class="radio">
                      <span class="radio-inner"> </span>
                    </span>
                    个人
                  </label>
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">
                  <span class="required">*</span>
                  类型
                </div>
                <div class="item-input-wrapper">
                  <label class="radio-input-wrapper">
                    <input
                      type="radio"
                      class="publish-input publish-radio-input"
                      name="type-radio"
                      value="算法需求"
                    />
                    <span class="radio">
                      <span class="radio-inner"> </span>
                    </span>
                    算法需求
                  </label>
                  <label class="radio-input-wrapper">
                    <input
                      type="radio"
                      class="publish-input publish-radio-input"
                      name="type-radio"
                    />
                    <span class="radio">
                      <span class="radio-inner"> </span>
                    </span>
                    硬件需求
                  </label>
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">
                  <span class="required">*</span>
                  公司名称
                </div>
                <div class="item-input-wrapper" style="width: 250px">
                  <input
                    class="publish-input"
                    type="text"
                    placeholder="请填写公司名称"
                  />
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">
                  <span class="required">*</span>
                  联系人姓名
                </div>
                <div class="item-input-wrapper" style="width: 250px">
                  <input
                    class="publish-input"
                    type="text"
                    placeholder="请填写联系人姓名"
                  />
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">
                  <span class="required">*</span>
                  手机号码
                </div>
                <div class="item-input-wrapper" style="width: 250px">
                  <input
                    class="publish-input"
                    type="text"
                    placeholder="请填写手机号码"
                  />
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">
                  <span class="required">*</span>
                  地区
                </div>
                <div>
                  <Select v-model="model1" style="width: 200px">
                    <Option
                      v-for="item in cityList"
                      :value="item.value"
                      :key="item.value"
                      >{{ item.label }}</Option
                    >
                  </Select>
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">开发周期</div>
                <div class="item-input-wrapper" style="width: 250px">
                  <input
                    class="publish-input"
                    type="text"
                    placeholder="请填写预计开发所用时间"
                  />
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">
                  <span class="required">*</span>
                  需求描述
                </div>
                <div class="item-input-wrapper">
                  <textarea
                    class="publish-input"
                    wrap="soft"
                    autocomplete="off"
                    spellcheck="false"
                    placeholder="请描述需求详情"
                    rows="2"
                    style="
                      margin-top: 0px;
                      margin-bottom: 0px;

                      min-height: 22px;
                      resize: vertical;
                    "
                  ></textarea>
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">达标要求</div>
                <div class="item-input-wrapper">
                  <input
                    class="publish-input"
                    type="text"
                    placeholder="请填写达标要求"
                  />
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">硬件要求</div>
                <div class="item-input-wrapper">
                  <input
                    class="publish-input"
                    type="text"
                    placeholder="请填写硬件要求"
                  />
                </div>
              </div>
              <div class="publish-item">
                <div class="publish-item-name">系统和软件版本</div>
                <div class="item-input-wrapper">
                  <input
                    class="publish-input"
                    type="text"
                    placeholder="请填写系统和软件版本"
                  />
                </div>
              </div>
            </div>
          </div>
          <div class="publish-bottom">
            <button
              class="publish-btn"
              style="background-color: white"
              @click="close()"
            >
              取消
            </button>
            <button
              class="publish-btn"
              style="background-color: #8c30f5; color: white"
              @click="confirm()"
            >
              确定
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  name: "publish",
  data() {
    return {
      cityList: [
        {
          value: "全国",
          label: "全国",
        },
        {
          value: "北京市",
          label: "北京市",
        },
        {
          value: "天津市",
          label: "天津市",
        },
        {
          value: "上海市",
          label: "上海市",
        },
        {
          value: "重庆市",
          label: "重庆市",
        },
        {
          value: "河北省",
          label: "河北省",
        },
        {
          value: "山西省",
          label: "山西省",
        },
        {
          value: "辽宁省",
          label: "辽宁省",
        },
        {
          value: "吉林省",
          label: "吉林省",
        },
        {
          value: "黑龙江省",
          label: "黑龙江省",
        },
        {
          value: "江苏省",
          label: "江苏省",
        },
        {
          value: "浙江省",
          label: "浙江省",
        },
        {
          value: "安徽省",
          label: "安徽省",
        },
        {
          value: "福建省",
          label: "福建省",
        },
        {
          value: "江西省",
          label: "江西省",
        },
        {
          value: "山东省",
          label: "山东省",
        },
        {
          value: "河南省",
          label: "河南省",
        },
        {
          value: "湖北省",
          label: "湖北省",
        },
        {
          value: "湖南省",
          label: "湖南省",
        },
        {
          value: "广东省",
          label: "广东省",
        },
        {
          value: "海南省",
          label: "海南省",
        },
        {
          value: "四川省",
          label: "四川省",
        },
        {
          value: "贵州省",
          label: "贵州省",
        },
        {
          value: "云南省",
          label: "云南省",
        },
        {
          value: "陕西省",
          label: "陕西省",
        },
        {
          value: "甘肃省",
          label: "甘肃省",
        },
        {
          value: "青海省",
          label: "青海省",
        },
        {
          value: "台湾省",
          label: "台湾省",
        },
        {
          value: "内蒙古自治区",
          label: "内蒙古自治区",
        },
        {
          value: "广西壮族自治区",
          label: "广西壮族自治区",
        },
        {
          value: "西藏自治区",
          label: "西藏自治区",
        },
        {
          value: "宁夏回族自治区",
          label: "宁夏回族自治区",
        },
        {
          value: "新疆维吾尔自治区",
          label: "新疆维吾尔自治区",
        },
      ],
      model1: "",
      warning: "haha",
    };
  },
  methods: {
    // 关闭发布需求的信息框
    close() {
      let input = document.getElementsByClassName("publish-input")
      input[0].value = "";
      this.model1 = "";
      for (let index = 1; index < 5; index++) {
        input[index].checked = false;
      }
      for (let index = 5; index < 13; index++) {
        input[index].value = "";
      }
      document.getElementsByClassName("publish-wrapper")[0].style.display =
        "none";
    },
    // 点击确定后发送请求
    confirm() {
      let input = document.getElementsByClassName("publish-input");
      // 判断是否填完必填信息
      if (
        !input[0].value ||
        (!input[1].checked && !input[2].checked) ||
        (!input[3].checked && !input[4].checked) ||
        !input[5].value ||
        !input[6].value ||
        !input[7].value ||
        !this.model1 ||
        !input[9].value
      ) {
        this.$emit("send", "必填信息未填满", "yellow");
        return 0;
      }
      // 判断手机号码是否符合标准
      let rightPhone = /^1[34578][0-9]{9}$/;
      if (!rightPhone.test(input[8].value)) {
        this.$emit("send", "填写正确的手机号码", "yellow");
        return 0;
      }
      // 获取radio单选框的内容
      let team = "企业";
      let type = "算法需求";
      if (!input[1].checked) {
        team = "个人";
      }
      if (!input[3].checked) {
        type = "硬件需求";
      }
      axios({
        url: "/api/request/insertRequest",
        method: "POST",
        data: {
          title: input[0].value,
          team: team,
          requestType: type,
          company: input[5].value,
          contact: input[6].value,
          phone: input[7].value,
          area: this.model1,
          period: input[8].value,
          content: input[9].value,
          standard: input[10].value,
          requires: input[11].value,
          version: input[12].value,
          userId: this.$route.params.userData.id,
        },
      }).then(() => {
        input[0].value = "";
        this.model1 = "";
        for (let index = 1; index < 5; index++) {
          input[index].checked = false;
        }
        for (let index = 5; index < 13; index++) {
          input[index].value = "";
        }
        this.warning = "发布成功";
        document.getElementsByClassName(
          "little-point"
        )[0].style.backgroundColor = "green";
        document.getElementsByClassName("publish-wrapper")[0].style.display =
          "none";
        this.$emit("send", "发布成功");
      });
    },
  },
};
</script>
<style>
.publish-wrapper {
  display: none;
  color: rgb(81, 90, 110);
}

.publish-mask {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(55, 55, 55, 0.6);
  height: 100%;
  z-index: 1114;
}

.publish-banner-wrapper {
  position: fixed;
  overflow: auto;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 1114;
  outline: 0;
}

.publish-banner {
  width: 820px;
  margin: 0 auto;
  position: relative;
  outline: none;
  top: 100px;
}

.publish-content {
  position: relative;
  background-color: #fff;
  border: 0;
  border-radius: 6px;
  background-clip: padding-box;
  box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}

.publish-close {
  z-index: 1;
  font-size: 12px;
  position: absolute;
  right: 8px;
  top: 8px;
  overflow: hidden;
  cursor: pointer;
}

.publish-close > i {
  font-size: 24px;
  color: #999;
  transition: color 0.2s ease;
  position: relative;
  top: 1px;
}

.publish-header {
  border-bottom: 1px solid #e8eaec;
  padding: 14px 16px;
  line-height: 1;
}

.publish-main {
  padding: 16px;
  font-size: 14px;
  line-height: 1.5;
}

.publish-message-box {
  margin: 20px 40px;
}

.publish-item {
  margin-bottom: 16px;
}

.publish-item-name {
  margin-bottom: 5px;
}

.required {
  color: red;
}

.clearfix::after,
.clearfix::before {
  content: "";
  display: table;
  clear: both;
}

.item-input-wrapper {
  display: inline-block;
  width: 100%;
  position: relative;
  vertical-align: middle;
  line-height: normal;
}

.publish-input {
  outline: none;
  display: inline-block;
  width: 100%;
  height: 32px;
  line-height: 1.5;
  padding: 4px 7px;
  font-size: 14px;
  border: 1px solid #dcdee2;
  border-radius: 4px;
  color: #515a6e;
  background-color: #fff;
  background-image: none;
  position: relative;
  cursor: text;
  transition: border 0.2s ease-in-out, background 0.2s ease-in-out,
    box-shadow 0.2s ease-in-out;
}

.publish-input:hover {
  border-color: #a359f7;
}
.radio-input-wrapper {
  font-size: 14px;
  vertical-align: middle;
  display: inline-block;
  position: relative;
  white-space: nowrap;
  margin-right: 8px;
  cursor: pointer;
}

.radio {
  display: inline-block;
  margin-right: 4px;
  position: relative;
  line-height: 1;
  vertical-align: middle;
  cursor: pointer;
  width: 14px;
  height: 14px;
  border: 1px solid #8c30f5;
  border-radius: 50%;
}

.publish-radio-input:checked + .radio .radio-inner::after {
  position: absolute;
  width: 8px;
  height: 8px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  display: table;
  content: " ";
  background-color: #8c30f5;
  transition: all 0.2s ease-in-out;
}

.publish-radio-input {
  display: none;
}

textarea::-webkit-input-placeholder {
  opacity: 0.5;
}

.publish-bottom {
  border-top: 1px solid #e8eaec;
  padding: 12px 18px 12px 18px;
  text-align: right;
}

.publish-btn {
  color: #515a6e;
  display: inline-block;
  margin-bottom: 0;
  font-weight: 400;
  text-align: center;
  vertical-align: middle;

  cursor: pointer;
  border: 1px solid transparent;
  height: 32px;
  padding: 0 15px;
  font-size: 14px;
  border-radius: 4px;
  outline: none;
}
</style>